<!-- 档案列表 -->
<template>
	<view class="user-card-list">
		<view class="user-card" :class="{'active': item.numcard == current_user_card.numcard}"
			v-for="(item, index) in userCardList" :key="index" @click.stop="changeCurrentUserCard(item)">

			<view class="left-wrapper" v-if="item.numcard == current_user_card.numcard">
				<uni-icons type="checkmarkempty" size="20" color="while"></uni-icons>
			</view>
			<view class="content-wrapper">
				<p>{{item.names}}</p>
				<p>ID: {{item.numcard}}</p>
			</view>


			<!-- <view class="right-wrapper">
				<u-button type="" size="small" text="解绑" @click.stop="unbind"></u-button>
			</view> -->
		</view>

		<button style="margin-top: 10px;" type="primary" @click="goToPage('/pagesB/healthCard/healthLogin')">在线建档</button>
		<button style="margin-top: 10px;" type="primary" @click="goToPage('/pagesB/healthCard/facePage')">人脸测试</button>
		<!-- 
		<button style="margin-top: 10px;" type="primary" @click="test()">测试</button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current_user_card: {
					numcard: ''
				},
				userCardList: []
			}
		},
		onLoad() {
			this.api_cardlist()
		},
		onShow() {
			this.current_user_card = uni.getStorageSync('current_user_card')
		},
		methods: {
			test() {
				uni.navigateTo({
					url: '/pagesB/healthCard/test'
				})
			},
			goToPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			changeCurrentUserCard(item) {
				uni.setStorageSync('current_user_card', item)
				uni.switchTab({
					url: '/pages/tabbar/index/index'
				});
			},
			api_cardlist() {
				let openid = uni.getStorageSync('openid')
				this.$app._post_form("entry/wxapp/apipatient.cardlist", {
					'openid': openid
				}, (res) => {
					if (res.status === 1) {
						this.userCardList = res.data
					}
				})
			},
			unbind() {
				console.log(123)
			}
		}
	}
</script>

<style scoped lang="scss">
	.user-card-list {
		padding: 15px;
		background-color: #EFEFF4;

		.user-card {
			padding: 10px;
			background-color: #fff;
			border-radius: 6px;
			margin-bottom: 10px;
			display: flex;
			flex-direction: row;

			.left-wrapper {
				display: flex;
				flex-direction: row;
				align-items: center;
				text-align: center;
				justify-content: center;
				color: #fff;
			}

			.content-wrapper {
				display: flex;
				flex: 1;
				flex-direction: column;
				padding-left: 10px;
			}

			.right-wrapper {
				display: flex;
				flex-direction: row;
				justify-content: flex-end;
				align-items: center;
			}

			&.active {
				background-color: #4caf50;
				color: #fff;
			}
		}
	}
</style>